import math
def is_prime(nemoy):
    if nemoy < 2:
        return False
    for i in range(2, int(math.sqrt(nemoy)) + 1):
        if nemoy % i == 0:
            return False
    return True
def closest_prime(num):
    if is_prime(num):
        return num
    lower_prime = num - 1
    upper_prime = num + 1
    while not is_prime(lower_prime):
        lower_prime -= 1
    while not is_prime(upper_prime):
        upper_prime += 1
    if num - lower_prime <= upper_prime - num:
        return lower_prime
    else:
        return upper_prime
word_to_num = {
    "zero": 0, "one": 1, "two": 2, "three": 3, "four": 4,
    "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9
}
words = input().split()
if len(words) != 3 or not all(word in word_to_num for word in words):
    print("Wrong input")
else:
    number = int("".join(str(word_to_num[word]) for word in words))
    print(closest_prime(number))
